import { Module, forwardRef } from '@nestjs/common'
import { PassportModule } from '@nestjs/passport'
import { UserModule } from '../user/user.module'
import { AuthService } from './auth.service'
import { AuthStrategy } from './auth.strategy'
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config'
@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    // forwardRef(() => UserModule), // 处理模块间的循环依赖
    JwtModule.register({
      secret: 'secretKey',
      signOptions: { expiresIn: '30m' }, // token 过期时效
    }),
    // JwtModule.registerAsync({
    //   imports: [ConfigModule],
    //   useFactory: async (config: ConfigService) => ({
    //     secret: 'secretKey',
    //     signOptions: {
    //       expiresIn: '2h'
    //     }
    //   }),
    // }),
  ],
  providers: [AuthService, AuthStrategy],
  exports: [AuthService] // 导出 authService 供 UserModule 使用
})
export class AuthModule {}
